#include<stdio.h>
#include<stdlib.h>
#include<string.h>


// 按字符操作文件
void test(){
    //写文件    w+不存在会创建
    FILE * f_write = fopen("./test.txt","w+");   
    if (f_write ==NULL){
        return;
    }

    char buf[]= "try write";
    for(int i=0;i<strlen(buf);i++){
        fputc(buf[i], f_write);
    }

    fclose(f_write);

    // 读文件
    FILE * f_read =  fopen("./test.txt","r");
    if(f_read == NULL){
        return;
    }
    char ch;
    while( (ch=fgetc(f_read))!=EOF ){
        printf("%c", ch);
    }

    fclose(f_read);
}

void main(){
    test();
}